'''
模拟播放器
'''

import sys
 
from Ui_player import *
from PySide6.QtCore import QUrl
from PySide6.QtMultimedia import QAudioOutput, QMediaPlayer
from PySide6.QtWidgets import QMainWindow, QApplication,QFileDialog
 
 
class MainWindow(QMainWindow):
    def __init__(self):
        super().__init__()
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)
        self._audio_output = QAudioOutput()
        self._player = QMediaPlayer()
        self._player.setAudioOutput(self._audio_output)
        self._player.setVideoOutput(self.ui._video_widget)

        self.ui.pushButton.clicked.connect(self._player.play)
        self.ui.stopButton.clicked.connect(self.open_file)
    def open_file(self):

        if not self._player.source():
            self._player.shop()
        options = QFileDialog.Options()
        file_path, _ = QFileDialog.getOpenFileName(None, "选择文件", "", "All Files (*)", options=options)
        self._player.setSource(QUrl.fromLocalFile(file_path))
        #暂停
        #self.ui.pauseButton.clicked.connect(self._player.pause)
        
 
 
if __name__ == '__main__':
    app = QApplication(sys.argv)
    main_win = MainWindow()
    main_win.setWindowTitle("Min_Player")
    main_win.show()

    #main_win.play()
    sys.exit(app.exec())